/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jfr_inicial.java
 *
 * Created on 27/10/2013, 06:02:03 PM
 */
package pkgVentanas;

import javax.swing.JOptionPane;
import pkgUtilidades.utlConstantes;

/**
 *
 * @author David
 */
public class vtnInicial extends javax.swing.JFrame {

    /** Creates new form jfr_inicial */
    public vtnInicial() {
        initComponents();
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Ejecutar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextField1.setText("500");

        jTextField2.setText("7");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(158, 158, 158)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(169, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(96, 96, 96)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(129, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        double nSueldo = Double.valueOf(jTextField1.getText().trim());
        double nFactorIni = ((nSueldo / utlConstantes.nTreita) / utlConstantes.nDos) / utlConstantes.nSeis;
        double nFactorFin = ((nSueldo / utlConstantes.nTreita) / utlConstantes.nDos) / utlConstantes.nSeite;
        double nSubFactor;
        double nAcumulado = 0;
        //---------------------------------
        int nMinutosAtraso = Integer.valueOf(jTextField2.getText().trim());
        int nTmpMinutosTraso;

        if (nMinutosAtraso >= utlConstantes.nTopMinutos)
        {
            nAcumulado = nFactorIni;

            if((nMinutosAtraso - utlConstantes.nTopMinutos) > 0)
            {
                nSubFactor = nFactorIni / (20 - utlConstantes.nTopMinutos);
                if(nMinutosAtraso > 20)
                    nTmpMinutosTraso = 20;
                else
                    nTmpMinutosTraso = nMinutosAtraso;

                nAcumulado = nAcumulado + (nSubFactor * (nTmpMinutosTraso - utlConstantes.nTopMinutos));
            }
            if((nMinutosAtraso - 20) > 0)
            {
                nSubFactor = (nFactorIni * 4) / (60 - 20);
                if(nMinutosAtraso > 60)
                    nTmpMinutosTraso = 60;
                else
                    nTmpMinutosTraso = nMinutosAtraso;

                nAcumulado = nAcumulado + (nSubFactor * (nTmpMinutosTraso - 20));
            }
            if((nMinutosAtraso - 60) > 0)
            {
                nSubFactor = nFactorFin / 60;
                if(nMinutosAtraso > 480)
                    nTmpMinutosTraso = 480;
                else
                    nTmpMinutosTraso = nMinutosAtraso;

                nAcumulado = nAcumulado + (nSubFactor * (nTmpMinutosTraso - 60));
            }
        }
        JOptionPane.showMessageDialog(null, nAcumulado);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new vtnInicial().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
}
